package com.enation.app.javashop.api.client;

import com.enation.app.javashop.framework.exception.ResourceNotFoundException;
import com.enation.app.javashop.framework.exception.ServiceException;
import com.enation.app.javashop.framework.util.FileUtil;
import com.enation.app.javashop.model.base.dto.FileDTO;
import com.enation.app.javashop.model.base.vo.FileVO;
import com.enation.app.javashop.model.errorcode.SystemErrorCode;
import com.enation.app.javashop.service.base.plugin.upload.Uploader;
import com.enation.app.javashop.service.base.service.FileManager;
import com.enation.app.javashop.service.system.factory.UploadFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import java.io.IOException;

/**
 * @author fk
 * @version v2.0
 * @Description:
 * @date 2018/8/13 9:31
 * @since v7.0.0
 */
@RestController
@RequestMapping("/client/uploader")
@ApiIgnore
public class UploadFactoryClientController {


    @Autowired
    private UploadFactory uploadFactory;

    @Autowired
    private FileManager fileManager;

    @GetMapping
    public String getUrl(String url, Integer width, Integer height) {
        Uploader uploader = uploadFactory.getUploader();
        return uploader.getThumbnailUrl(url, width, height);
    }

    @RequestMapping(method = RequestMethod.POST,consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public FileVO uploadFile(@RequestPart(value = "file") MultipartFile file,@RequestParam("scene")String scene) throws IOException {

        return fileManager.uploadFile(file,scene);
    }

}
